package
{
	import flash.display.Bitmap;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;
	import flash.net.SharedObject;
	import flash.net.registerClassAlias;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;
	
	import ui.Button;
	import ui.List;
	import ui.ListItem;
	import ui.Panel;
	
	/**
	 * 添加音乐面板
	 */ 
	public class AddMusicPanel extends Panel
	{		
		private	var btnOk:Button = null;
		private	var btnCancel:Button = null;

		private	var	urlLabel:TextField = null;
		private	var urlInput:TextField = null;
		
		private	var nameLabel:TextField = null;
		private var nameInput:TextField = null;
		
		private	var artistLabel:TextField = null;
		private	var artistInput:TextField = null;
		
		private	var bgPanel:BgPanel = null;
		
		public function AddMusicPanel(bgPanel:BgPanel)
		{
			super(Asset.getPanelAdd());
			this.bgPanel = bgPanel;
			onInit();
		}
		
		public	function	onInit():void{			
			this.btnOk = new Button(60, 22, Asset.getButtonDefault());
			this.btnOk.text = "添 加";
			this.btnOk.x = 60;
			this.btnOk.y = this.height - this.btnOk.height - 10;
			this.btnOk.textColor = 0x927E60;
			this.btnOk.textFontSize = 14;
			this.addChild(this.btnOk);
			
			this.btnCancel = new Button(60, 22, Asset.getButtonDefault());
			this.btnCancel.text = "取 消";
			this.btnCancel.x = this.btnOk.getRight()+20;
			this.btnCancel.y = this.btnOk.y;
			this.btnCancel.textColor = 0x927E60;
			this.btnCancel.textFontSize = 15;
			this.addChild(this.btnCancel);
			
			this.urlLabel = new TextField();
			this.urlLabel.text = "URL:";
			this.urlLabel.x = 10;
			this.urlLabel.y = 40;
			this.urlLabel.height = 20;
			this.urlLabel.textColor = 0x927E60;
			var tf:TextFormat = new TextFormat();
			tf.size = 14;
			this.urlLabel.setTextFormat(tf);
			this.addChild(this.urlLabel);
			
			this.urlInput = new TextField();
			this.urlInput.type = TextFieldType.INPUT;
			this.urlInput.autoSize = TextFieldAutoSize.NONE;
			this.urlInput.x = 45;
			this.urlInput.y = 40;
			this.urlInput.width = 190;
			this.urlInput.height = 20;
			this.urlInput.background = true;
			this.urlInput.backgroundColor = 0xffffff;
			this.urlInput.border = true;
			this.urlInput.borderColor = 0x607E92;
			tf = new TextFormat();
			tf.size = 14;
			this.urlInput.text = "http://";
			this.urlInput.setTextFormat(tf);
			this.addChild(this.urlInput);	
			
			this.nameLabel = new TextField();
			this.nameLabel.text = "歌名:";
			this.nameLabel.x = 10;
			this.nameLabel.y = 70;
			this.nameLabel.height = 20;
			this.nameLabel.textColor = 0x927E60;
			tf.size = 14;
			this.nameLabel.setTextFormat(tf);
			this.addChild(this.nameLabel);
			
			this.nameInput = new TextField();
			this.nameInput.type = TextFieldType.INPUT;
			this.nameInput.autoSize = TextFieldAutoSize.NONE;
			this.nameInput.x = 45;
			this.nameInput.y = 70;
			this.nameInput.width = 190;
			this.nameInput.height = 20;
			this.nameInput.background = true;
			this.nameInput.backgroundColor = 0xffffff;
			this.nameInput.border = true;
			this.nameInput.borderColor = 0x607E92;
			tf = new TextFormat();
			tf.size = 14;
			this.nameInput.text = " ";
			this.nameInput.setTextFormat(tf);
			this.addChild(this.nameInput);
			
			this.artistLabel = new TextField();
			this.artistLabel.text = "歌手:";
			this.artistLabel.x = 10;
			this.artistLabel.y = 100;
			this.artistLabel.height = 20;
			this.artistLabel.textColor = 0x927E60;
			tf.size = 14;
			this.artistLabel.setTextFormat(tf);
			this.addChild(this.artistLabel);
			
			this.artistInput = new TextField();
			this.artistInput.type = TextFieldType.INPUT;
			this.artistInput.autoSize = TextFieldAutoSize.NONE;
			this.artistInput.x = 45;
			this.artistInput.y = 100;
			this.artistInput.width = 190;
			this.artistInput.height = 20;
			this.artistInput.background = true;
			this.artistInput.backgroundColor = 0xffffff;
			this.artistInput.border = true;
			this.artistInput.borderColor = 0x607E92;
			tf = new TextFormat();
			tf.size = 14;
			this.artistInput.text = " ";
			this.artistInput.setTextFormat(tf);
			this.addChild(this.artistInput);
			
			this.btnOk.addEventListener(MouseEvent.CLICK, onOkClick);
			this.btnCancel.addEventListener(MouseEvent.CLICK, onCancelClick);
		}
		
		public	function	onOkClick(evt:MouseEvent):void{
			this.visible = false;
			
			var item:ListItem = new ListItem();
			item.name = this.nameInput.text;
			item.url = this.urlInput.text;
			item.artist = this.artistInput.text;
			var list:List = this.bgPanel.getPlayList();
			list.addItem(item);
			
			//在本地保存播放列表
			var arrItem:Array = list.getItemList();
			var sl:StorageList = new StorageList();
			sl.setItemList(arrItem);
			var so:SharedObject = SharedObject.getLocal("musicPlayer");
			so.data.sl = sl.toString();
			so.flush();
		}
			
		public	function	onCancelClick(evt:MouseEvent):void{
			this.visible = false;
		}
	}
}